package com.ol.edu.server.service.advertise.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ol.edu.server.entity.PromotionSpace;
import com.ol.edu.server.mapper.PromotionSpaceMapper;
import com.ol.edu.server.service.advertise.PromotionSpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author Roger
 * @date 2020/9/7 10:17
 * @description
 */
@Service
public class PromotionSpaceServiceImpl implements PromotionSpaceService {
    @Autowired
    private PromotionSpaceMapper promotionSpaceMapper;
    /*
        获取广告位列表数据
     */
    @Override
    public List<PromotionSpace> findAllPromotionSpace() {
        List<PromotionSpace> promotionSpaceList = promotionSpaceMapper.findAllPromotionSpace();
        return promotionSpaceList;
    }

    /*
        获取广告位列表数据
     */
    @Override
    public PageInfo<PromotionSpace> findAllPromotionSpaceByPage(Integer currentPage, Integer pageSize) {
        //分页
        PageHelper.startPage(currentPage, pageSize);
        List<PromotionSpace> promotionSpaceList = promotionSpaceMapper.findAllPromotionSpace();
        PageInfo<PromotionSpace> pageInfo = new PageInfo<>(promotionSpaceList);
        return pageInfo;
    }
    /*
        添加广告位
     */
    @Override
    public void savePromotionSpace(PromotionSpace promotionSpace) {
        Date date = new Date();
        promotionSpace.setCreateTime(date);
        promotionSpace.setUpdateTime(date);
        promotionSpace.setIsDel(0);
        promotionSpace.setSpaceKey(UUID.randomUUID().toString());

        promotionSpaceMapper.savePromotionSpace(promotionSpace);
    }
    /*
        修改广告位
     */
    @Override
    public void updatePromotionSpace(PromotionSpace promotionSpace) {
        promotionSpace.setUpdateTime(new Date());

        promotionSpaceMapper.updatePromotionSpace(promotionSpace);
    }
    /*
        回显广告位名称
     */
    @Override
    public PromotionSpace findPromotionSpaceById(Integer id) {
        PromotionSpace promotionSpace = promotionSpaceMapper.findPromotionSpaceById(id);
        return promotionSpace;
    }
}
